#ifndef HRVDATAPROCESS_H
#define HRVDATAPROCESS_H

#define PPG_DATA_LEN 90000
#define DATA_LEN1 1700
#include "HRVPro/appgalg.h"
#include "Beans/HRVData.h"
#include "Beans/userinfobeab.h"
class HRVDataProcess
{
public:
    HRVDataProcess();
    ~HRVDataProcess();
    void InitHrvParameter(void);
    void setAge(int age,int gender);//男为0，女为1
    double Cacul_Psi(int* rr_buf, int rr_len, int* a7, int len);
    double Cacul_Apen(int rr_len, int* rr_buf);
    void fit_rr(int* rr_raw_buf, double* rr_fit_buf, int data_len);
    void ResampleRR(double* fit_rr_buf, int fit_rr_len);
    int cal_fft_len(int len);
    void PreprocessResampleRR(double* rs_rr_buf);
    void ComputeHRV(int* p_data_buf, int Len);
    void GetResult();
    double Cal_TpScore(double tp, int age,int gender);
    double Cal_MsiScore(double ratio, int age,int gender);
    double CalSdnnScore(double sdnn, int age,int gender);
    double CalPsiScore(double psi, int age,int gender);
    double CalLfScore(double lf, int age,int gender);
    double CalHfScore(double hf, int age,int gender);
    void CalHrtstate(double mean_hrt, int age,int gender);
    double Cal_TotolScore(double psiscore, double sdnnscore, double msiscore);
    double Cal_ANSBalance(double lfnorm,int age,int gender);
    double Cal_ANSBalanceState(double ans_lance, int age);
    double Cacul_Emotion(double lfhf);
    HRVIndex getHRVIndex();
    QString HRVData2Json(HRVIndex hi,QList<double>sub_ppg,UserInfoBeab uib);
    HRVIndex Json2HRVData(QString json);
    void getSLIndex(QList<int>rr,QList<double>spox,QList<double>perfustion);
    //PPG_DATA_LEN
    double  Resample_rr_buf[PPG_DATA_LEN / 250];
    double  PrePro_rr_buf[PPG_DATA_LEN / 250];
    int a7[DATA_LEN1 * 4];
    double* f;
    double* dst;
    double* g_RRFitBuf;
    int rr_abnormal_count = 0;
    double MeanNN;
    double MeanHrt;
    double MaxHrt;
    double MinHrt;
    double Sdnn;
    double pNN50;
    int NN50;
    int DRR;
    double CV;
    double SDSD;
    double Rmssd;
    double Psi;
    double Apen;
    double Srd;
    double Tsrd;
    double TP;
    double VLF;
    double LF;
    double HF;
    double LFNorm;
    double HFNorm;
    double LFHFRatio;
    QList<int>RRList;
    QList<int>rr;
    QList<double>ppgforAppg;
    double Spox,perfusion;
    double HrvParameters[22436];
    int TP_State= 0;
    int MSI_State = 0;
    int PSI_State = 0;
    int SDNN_Sate = 0;
    int LF_State = 0;
    int HF_State = 0;
    int HRT_State = 0;
    int age,gender;
    double tpScore;
    double MsiScore;
    double SdnnScore;
    double PsiScore;
    double lfScore;
    double hfScore;
    double AnsScore ;
    int Ans_State;
    double TotalScore ;
    double EmotionScore;
    QString HRV_Res;
    QString SL_Res;
    QString MentalPress_Res;
    QString Ans_Res;
    AppgAlg *appgalg;
};

#endif // HRVDATAPROCESS_H
